const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;

const buf1 = Buffer.from(arr); // 拷贝了该 buffer
const buf2 = Buffer.from(arr.buffer); // 与该数组共享了内存

console.log(buf1);
// 输出: <Buffer 88 a0>, 拷贝的 buffer 只有两个元素
console.log(buf2);
// 输出: <Buffer 88 13 a0 0f>

arr[1] = 6000;
console.log(buf1);
// 输出: <Buffer 88 a0>
console.log(buf2);
// 输出: <Buffer 88 13 70 17>

const StringDecoder = require('string_decoder').StringDecoder;
const decoder = new StringDecoder('utf8');

const cent = Buffer.from([0xC2, 0xA2]);
console.log(decoder.write(cent)); // ¢

const euro = Buffer.from([0xE2, 0x82, 0xAC]);
console.log(decoder.write(euro)); // €

//const StringDecoder = require('string_decoder').StringDecoder;
const decoder2 = new StringDecoder('utf8');

decoder2.write(Buffer.from([0xE2]));
decoder2.write(Buffer.from([0x82]));
console.log(decoder2.end(Buffer.from([0xAC])));  // €

console.log(process.stdin.fd); // 0
console.log(process.stdout.fd); // 1
console.log(process.stderr.fd); // 2

const readline = require('readline');
const fs = require('fs');

const rl = readline.createInterface({
  //input: fs.createReadStream('c:/HaxLogs.txt')
  input:process.stdin
});

rl.on('line', (line) => {
  console.log(`Line from file: ${line}`);
});